package org.csmzxy.class2333;
import java.util.HashSet;
import java.util.Iterator;
class Student{
    String stuId;//学号
    String stuName;//姓名
    public Student(String stuId ,String stuName){
        this.stuId = stuId;
        this.stuName =stuName;
    }
    public String toString(){ //重写toString()方法
        return "学号:"+stuId+"姓名:"+stuName;
    }
    public int hashCode(){
        return stuId.hashCode();//获取stuId的哈希值
    }
    public boolean equals(Object obj){
        if (this==obj){
            return true;
        }
        if(obj==null || !(obj instanceof Student)){
            return false;
        }
        Student student =(Student) obj;
        return this.stuId.equals(student.stuId);
    }
}
public class Example08 {
    public static void main(String[]args){
        HashSet<Student> set =new HashSet<>();
        set.add(new Student("01","张三"));
        set.add(new Student("02","李四"));
        set.add(new Student("02","李四"));
        Iterator<Student> iterator =set.iterator();
        while (iterator.hasNext()){
            Student student =iterator.next();
            System.out.println(student.toString());
        }
    }
}
